//
//  YJBlankView.m
//  CToolBox
//
//  Created by crj on 2016/10/20.
//  Copyright © 2016年 oyf. All rights reserved.
//

#import "YJBlankView.h"

@interface YJBlankView()
{
    UIColor *_dataViewColor;
}

@property (nonatomic, strong) UIImageView *blankImageView;
@property (nonatomic, strong) UILabel *messageLabel;

@property (nonatomic, copy) NSString *message;

@property (nonatomic, strong) UIView *dataView;


@end

@implementation YJBlankView

+ (YJBlankView *)showBlankWithMessage:(NSString *)message superView:(UIView *)superView frame:(CGRect)frame dataView:(UIView *)dataView{

    YJBlankView *blankView = [[YJBlankView alloc] initWithMessage:message superView:superView frame:frame dataView:dataView];
    return blankView;
}



- (id)initWithMessage:(NSString *)message superView:(UIView *)superView frame:(CGRect)frame dataView:(UIView *)dataView
{
    self = [super init];
    if (self) {
        self.hidden = YES;
        _dataView = dataView;
        _message = message;
        self.frame = frame;
        [superView addSubview:self];
        [superView sendSubviewToBack:self];
        [self setUI];
        
        _dataViewColor = _dataView.backgroundColor;

    }
    return self;
}



- (void)reloadBlankViewWithCount:(NSInteger)count{
    
    if(count == 0){
        self.hidden = NO;
        _dataView.hidden = YES;
        _dataView.backgroundColor = [UIColor clearColor];
    }else{
        self.hidden = YES;
        _dataView.hidden = NO;
        _dataView.backgroundColor = _dataViewColor;
    }
}



- (void)setUI{
    
    _blankImageView = [[UIImageView alloc] init];
    _blankImageView.image = [UIImage imageNamed:@"页面空白图"];
    
    _messageLabel = [[UILabel alloc] init];
    _messageLabel.numberOfLines = 0;
    _messageLabel.textAlignment = NSTextAlignmentCenter;
    _messageLabel.font = [UIFont systemFontOfSize:13];
    _messageLabel.textColor = HEXCOLOR(kColorGray2, 1);
    _messageLabel.text = _message;
    
    [self addSubview:_blankImageView];
    [self addSubview:_messageLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat space = 20;
    
    _blankImageView.frame = CGRectMake(0, 0, 150, 195);
    [_blankImageView sizeToFit];
    _blankImageView.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2-50);
    
    _messageLabel.frame = CGRectMake(space, _blankImageView.yj_bottom+space, self.frame.size.width-space*2, 0);
    [_messageLabel sizeToFit];
    _messageLabel.center = CGPointMake(_blankImageView.center.x, _messageLabel.center.y);
    
    
}




@end
